package pierwszy;

import org.openqa.selenium.NoSuchWindowException;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.ui.Select;
import org.openqa.selenium.support.ui.WebDriverWait;

public class NotePage extends Note{
	private WebDriver driver;
	private WebDriverWait wait;
	private Select noteType;
	private String notesListPageHeader = "Notka (dodaj notkę)";
	
	NotePage(WebDriver driver, WebDriverWait wait){
		super(driver, wait);
		this.driver = driver;
		this.wait = wait;
		
		if(!getNotePageHeader().getText().equals(notesListPageHeader)){
			throw new NoSuchWindowException("This is not the Note page");
		}

//		if(!getIconPlusText().getText().equals(KsPDKPage.iconPlusOptionsMap.get("Notkę"))){
//			throw new NoSuchWindowException("This is not the Note page");
//		}
	}
	
	public NotePage typeNoteText(String noteTxt){
		WebElement noteText = driver.findElement(NotePageUiMapping.noteTextArea);
		noteText.sendKeys(noteTxt);
		
		return this;
	}
	
	/**
	* @param noteTypeText valid Strings: "Publiczna" or "Prywatna"
	*/
	public NotePage selectNoteType(String noteTypeText){
		noteType = new Select(driver.findElement(NotePageUiMapping.noteTypeSelect));
		noteType.selectByVisibleText(noteTypeText);
		
		return this;
	}
	
	public NotesListPage submitNewNote(){
		WebElement submitNote = driver.findElement(NotePageUiMapping.noteSubmitBtn);
		submitNote.click();
		
		return new NotesListPage(driver,wait);
	}
	
	/**
	* @param noteType valid Strings: "Publiczna" or "Prywatna"
	* @param noteText notes content
	*/
	public NotesListPage addNewNote(String noteType, String noteText){
		selectNoteType(noteType);
		typeNoteText(noteText);
		
		return submitNewNote();
	}
	
	//getters
	public WebElement getNotePageHeader(){
		return driver.findElement(NotesListPageUiMapping.notesListPageHeader);
	}
}
